﻿CREATE TABLE [dbo].[Orders] (
    [id]                  INT              IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL,
    [OId]                 UNIQUEIDENTIFIER CONSTRAINT [DF_Orders_OId] DEFAULT (newid()) ROWGUIDCOL NOT NULL,
    [OrderId]             NVARCHAR (50)    NOT NULL,
    [CustomerId]          NVARCHAR (50)    NOT NULL,
    [CustomerName]        NVARCHAR (50)    NULL,
    [ContactPerson]       NVARCHAR (50)    NULL,
    [ContactPhone]        NVARCHAR (50)    NULL,
    [UserName]            NVARCHAR (50)    NULL,
    [EName]               NVARCHAR (50)    NULL,
    [FixtureDate]         DATETIME         NULL,
    [Description]         VARCHAR (MAX)    NULL,
    [Aggregateamount]     NUMERIC (18, 2)  NULL,
    [Proceeds]            NUMERIC (18, 2)  NULL,
    [CreateDate]          DATETIME         NULL,
    [CompanyId]           INT              NULL,
    [FinanceFlag]         BIT              NULL,
    [ProjectFlag]         BIT              CONSTRAINT [DF_Orders_ProjectFlag] DEFAULT ((0)) NULL,
    [PaymentTypeId]       INT              NULL,
    [ProductId]           INT              NULL,
    [DepartmentId]        INT              CONSTRAINT [DF_Orders_DepartmentId] DEFAULT ((0)) NULL,
    [BaiDuAccount]        NVARCHAR (50)    NULL,
    [MainProjectId]       INT              CONSTRAINT [DF_Orders_MainProjectId] DEFAULT ((0)) NULL,
    [IsReason]            BIT              CONSTRAINT [DF_Orders_IsReason] DEFAULT ((0)) NULL,
    [TrackKf]             NVARCHAR (50)    NULL,
    [TrackKfDepartmentId] INT              NULL,
    [StateId]             INT              CONSTRAINT [DF_Orders_StateId] DEFAULT ((0)) NULL,
    [TichengFlag]         BIT              CONSTRAINT [DF_Orders_TichengFlag] DEFAULT ((0)) NULL,
    [TiCheng]             NUMERIC (18, 2)  CONSTRAINT [DF_Orders_TiCheng] DEFAULT ((0)) NULL,
    CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED ([id] ASC)
);


GO


-- =============================================
-- Author:		<王鑫鹏>
-- Create date: <2011-05-03>
-- Description:	<删除订单触发器>
-- =============================================
CREATE TRIGGER [Orders_Deleted] On [dbo].[Orders] 
AFTER DELETE
AS 
BEGIN
	Insert Into Recycler_Orders
	(		[Id]
		   ,[OId]
           ,[OrderId]
           ,[CustomerId]
           ,[CustomerName]
           ,[ContactPerson]
           ,[ContactPhone]
           ,[UserName]
           ,[EName]
           ,[FixtureDate]
           ,[Aggregateamount]
           ,[Proceeds]
           ,[CreateDate]
           ,[CompanyId]
           ,[FinanceFlag]
           ,[ProjectFlag]
           ,[PaymentTypeId]
           ,[ProductId]
           ,[DepartmentId]
           ,[BaiDuAccount]
           ,[MainProjectId]
           ,[IsReason]
	)	
	Select 
			[Id]
		   ,[OId]
           ,[OrderId]
           ,[CustomerId]
           ,[CustomerName]
           ,[ContactPerson]
           ,[ContactPhone]
           ,[UserName]
           ,[EName]
           ,[FixtureDate]
           ,[Aggregateamount]
           ,[Proceeds]
           ,[CreateDate]
           ,[CompanyId]
           ,[FinanceFlag]
           ,[ProjectFlag]
           ,[PaymentTypeId]
           ,[ProductId]
           ,[DepartmentId]
           ,[BaiDuAccount]
           ,[MainProjectId]
           ,[IsReason]
	From Deleted
END

